<template>
  <avue-crud :option="option"
             :table-loading="loading"
             :data="data"
             v-model:page="page"
             v-model="form"
             ref="crud"
             @search-change="searchChange"
             @search-reset="searchReset"
             @selection-change="selectionChange"
             @current-change="currentChange"
             @size-change="sizeChange"
             @on-load="onLoad">
  </avue-crud>
</template>

<script>


export default {
  name: 'deviceTask',
  props: {
    productKey: String,
    deviceId: String,
  },
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height: 'auto',
        calcHeight: 32,
        header: false,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        addBtn: false,
        viewBtn: true,
        selection: true,
        menu: true,
        emptyText: '当前设备尚未执行任何任务',
        dialogWidth: 500,
        labelWidth: 120,
        searchLabelWidth: 100,
        column: [
          {
            label: "任务名称",
            prop: "taskName",
            type: "input",
            span: 24,
          },
          {
            label: "任务ID",
            prop: "taskId",
            type: "input",
            search: true,
            span: 24,
          },
          {
            label: "作业ID",
            prop: "jobId",
            type: "input",
            search: true,
            span: 24,
          },
          {
            label: "作业排队时间",
            prop: "jobQueueTime",
            type: "input",
            span: 24,
          },
          {
            label: "作业更新时间",
            prop: "jobUpdateTime",
            type: "input",
            span: 24,
          },
          {
            label: "进度",
            prop: "progress",
            type: "input",
            span: 24,
          },
          {
            label: "作业状态",
            prop: "jobStatus",
            type: "input",
            span: 24,
          },
        ]
      },
      data: []
    };
  },
  computed: {
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad(page, params = {}) {
      this.loading = true;
      this.loading = false;
    }
  }
};
</script>

<style>
</style>
